﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMS.Resources;
using PMS.BLL;
using PMS.Entity;
using PMS.Win;
using PMS.Utils;

namespace PMS
{
    public partial class LoginForm : FormManualBase
    {
        private string LOGIN_FAIL = "LOGIN_FAIL";
        private AccountBO m_Service;

        public LoginForm()
        {
            InitializeComponent();
        }

        public AccountBO Service 
        {
            get
            {
                if (m_Service == null)
                {
                    m_Service = new AccountBO();
                }
                return m_Service;
            }
        }

        private void Init()
        {
        }

        private void InitStyle()
        {

        }

        private void IinitData()
        {
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string Accountname = DataConvertUltils.ToString(txtUsername.EditValue);
                string pass = DataConvertUltils.ToString(txtPassword.EditValue);
                 CurrentUser = Service.login(Accountname, pass);
                 if (CurrentUser != null)
                {                    
                    this.DialogResult = DialogResult.OK;
                    IsLoggedIn = true;
                }
                else
                {
                    ShowErrorMessage(Messages.GetString(LOGIN_FAIL));
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

    }
}
